home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2 Examples.sit / Raven 1.2 Examples / Quill / Source / WindowProxy.cpp < prev    next >
Text File  |  1997-09-08  |  7KB  |  268 lines

  1. /*
  2.  *  File:       WindowProxy.cpp
  3.  *  Summary:       A stand in for TWindow that behaves better when it's being edited.
  4.  *  Written by: Jesse Jones
  5.  *
  6.  *  Copyright ゥ 1996 Jesse Jones. 
  7.  *    For conditions of distribution and use, see copyright notice in ZTypes.h  
  8.  *
  9.  *  Change History (most recent first):    
  10.  *
  11.  *         <->    12/24/96    JDJ        Created
  12.  */
  13.  
  14. #include "WindowProxy.h"
  15.  
  16. #include <List.h>
  17.  
  18. #include <ZAttribute.h>
  19. #include <ZStream.h>
  20. #include <ZUndoMgr.h>
  21.  
  22. #include "Document.h"
  23. #include "ViewContainer.h"
  24.  
  25.  
  26. // ===================================================================================
  27. //    class CWindowProxy
  28. // ===================================================================================
  29.  
  30. static TReanimatorRegister<CWindowProxy> sWindowProxyRegistrar;
  31.  
  32. static TReanimatorRegister<CWindowProxy> sWindowRegistrar("TWindow");
  33.  
  34. bool CWindowProxy::msUseProxy = false;
  35.  
  36. //---------------------------------------------------------------
  37. //
  38. // CWindowProxy::~CWindowProxy
  39. //
  40. //---------------------------------------------------------------
  41. CWindowProxy::~CWindowProxy()
  42. {
  43.     // Delete the view container while we're still the right type.
  44.     this->DoDeleteSubPanes();
  45. }
  46.  
  47.  
  48. //---------------------------------------------------------------
  49. //
  50. // CWindowProxy::CWindowProxy ()
  51. //
  52. //---------------------------------------------------------------
  53. CWindowProxy::CWindowProxy() 
  54. {
  55.     this->AddAttribute("Editing", new TAttribute(kNonPersistant));
  56.     
  57.     if (mUndoContext == nil)
  58.         mUndoContext = new TUndoMgr;
  59.  
  60.     msUseProxy = false;
  61. }
  62.  
  63.             
  64. //---------------------------------------------------------------
  65. //
  66. // CWindowProxy::CWindowProxy (SWindowInfo, MCommander*)
  67. //
  68. //---------------------------------------------------------------
  69. CWindowProxy::CWindowProxy(const SWindowInfo& info, MCommander* superCommander) : TWindow(info, superCommander)
  70. {
  71.     mOldAttributes = mAttributes;
  72.     
  73.     mAttributes.hasCloseBox   = true;
  74.     mAttributes.resizable     = true;
  75.     mAttributes.clickThrough  = true;
  76.     mAttributes.eraseOnUpdate = false;
  77.     mAttributes.hideOnSuspend = false;
  78.     mAttributes.targetable    = true;
  79.     mAttributes.handleClicks  = true;
  80.     mAttributes.layer         = kRegularLayer;
  81.  
  82.     if (mUndoContext == nil)
  83.         mUndoContext = new TUndoMgr;
  84.  
  85.     this->AddAttribute("Editing", new TAttribute(kNonPersistant));
  86.     
  87.     msUseProxy = false;
  88. }
  89.  
  90.             
  91. //---------------------------------------------------------------
  92. //
  93. // CWindowProxy::Create                                    [static]
  94. //
  95. //---------------------------------------------------------------
  96. MReanimatable* CWindowProxy::Create(MReanimatable*)
  97. {    
  98.     if (msUseProxy)
  99.         return new CWindowProxy;
  100.     else
  101.         return new TWindow;
  102. }
  103.  
  104.  
  105. //---------------------------------------------------------------
  106. //
  107. // CWindowProxy::HandleClick
  108. //
  109. //---------------------------------------------------------------
  110. void CWindowProxy::HandleClick(const TMouseEvent& globalEvent, short partCode)
  111. {
  112.     TRect sizeBox = mWindowPtr->portRect;
  113.     sizeBox.left = sizeBox.right - 15;
  114.     sizeBox.top = sizeBox.bottom - 15;
  115.         
  116.     TPoint localPt = this->PortToLocal(this->GlobalToPort(globalEvent.GetPosition()));
  117.  
  118.     if (sizeBox.Contains(localPt))
  119.         partCode = inGrow;
  120.         
  121.     Inherited::HandleClick(globalEvent, partCode);
  122. }
  123.  
  124.  
  125. //---------------------------------------------------------------
  126. //
  127. // CWindowProxy::SetInfo
  128. //
  129. //---------------------------------------------------------------
  130. void CWindowProxy::SetInfo(const SWindowInfo& info)
  131. {
  132.     TDisableInvariant disable(this);        // otherwise will get ASSERT with non-targetable windows
  133.     
  134.     Inherited::SetInfo(info);
  135.     
  136.     mOldAttributes = mAttributes;
  137.  
  138.     mAttributes.hasCloseBox   = true;
  139.     mAttributes.resizable     = true;
  140.     mAttributes.clickThrough  = true;
  141.     mAttributes.eraseOnUpdate = false;
  142.     mAttributes.hideOnSuspend = false;
  143.     mAttributes.targetable    = true;
  144.     mAttributes.handleClicks  = true;
  145.     mAttributes.layer         = kRegularLayer;
  146. }
  147.  
  148. #pragma mark ハ
  149.  
  150. //---------------------------------------------------------------
  151. //
  152. // CWindowProxy::Invariant
  153. //
  154. //---------------------------------------------------------------
  155. void CWindowProxy::Invariant() const
  156. {
  157.     Inherited::Invariant();
  158.     
  159.     if (mSubPanes->size() > 0) {
  160.         ASSERT(mSubPanes->size() == 1);
  161.         
  162.         TPane* subPane = mSubPanes->front();
  163.         ASSERT(subPane != nil);
  164.  
  165.         ASSERT(dynamic_cast<CViewContainer*>(subPane) != nil);
  166.     }
  167. }
  168.  
  169.  
  170. //---------------------------------------------------------------
  171. //
  172. // CWindowProxy::OnStreamOut
  173. //
  174. //---------------------------------------------------------------
  175. void CWindowProxy::OnStreamOut(TOutStream& stream) const
  176. {
  177.     CWindowProxy* thisPtr = const_cast<CWindowProxy*>(this);
  178.  
  179.     thisPtr->mAttributes = mOldAttributes;
  180.  
  181.     try {
  182.         Inherited::OnStreamOut(stream);
  183.         
  184.         thisPtr->mAttributes.hasCloseBox   = true;
  185.         thisPtr->mAttributes.resizable     = true;
  186.         thisPtr->mAttributes.clickThrough  = true;
  187.         thisPtr->mAttributes.eraseOnUpdate = false;
  188.         thisPtr->mAttributes.hideOnSuspend = false;
  189.         thisPtr->mAttributes.targetable    = true;
  190.         thisPtr->mAttributes.handleClicks  = true;
  191.         thisPtr->mAttributes.layer         = kRegularLayer;
  192.         
  193.     } catch (...) {
  194.         thisPtr->mAttributes.hasCloseBox   = true;
  195.         thisPtr->mAttributes.resizable     = true;
  196.         thisPtr->mAttributes.clickThrough  = true;
  197.         thisPtr->mAttributes.eraseOnUpdate = false;
  198.         thisPtr->mAttributes.hideOnSuspend = false;
  199.         thisPtr->mAttributes.targetable    = true;
  200.         thisPtr->mAttributes.handleClicks  = true;
  201.         thisPtr->mAttributes.layer         = kRegularLayer;
  202.         
  203.         throw;
  204.     }
  205. }
  206.  
  207.  
  208. //---------------------------------------------------------------
  209. //
  210. // CWindowProxy::OnReanimated
  211. //
  212. //---------------------------------------------------------------
  213. void CWindowProxy::OnReanimated()
  214. {
  215.     Inherited::OnReanimated();
  216.     
  217.     mOldAttributes = mAttributes;
  218.  
  219.     mAttributes.hasCloseBox   = true;
  220.     mAttributes.resizable     = true;
  221.     mAttributes.clickThrough  = true;
  222.     mAttributes.eraseOnUpdate = false;
  223.     mAttributes.hideOnSuspend = false;
  224.     mAttributes.targetable    = true;
  225.     mAttributes.handleClicks  = true;
  226.     mAttributes.layer         = kRegularLayer;
  227.     
  228.     if (mUndoContext == nil)
  229.         mUndoContext = new TUndoMgr;
  230.  
  231.     TDesktop::Instance()->NormalizeWindowOrder();    
  232. }
  233.  
  234.  
  235. //---------------------------------------------------------------
  236. //
  237. // CWindowProxy::OnOpen
  238. //
  239. //---------------------------------------------------------------
  240. void CWindowProxy::OnOpen()
  241. {
  242.     Inherited::OnOpen();
  243.     
  244.     this->Show();
  245. }
  246.  
  247.  
  248. //---------------------------------------------------------------
  249. //
  250. // CWindowProxy::DoClickInGrow
  251. //
  252. //---------------------------------------------------------------
  253. void CWindowProxy::DoClickInGrow(const TMouseEvent& globalEvent)
  254. {
  255.     TSize oldSize = this->GetSize();
  256.     
  257.     Inherited::DoClickInGrow(globalEvent);
  258.     
  259.     TSize newSize = this->GetSize();
  260.     if (newSize != oldSize) {
  261.         CViewContainer* container = dynamic_cast<CViewContainer*>(mSubPanes->front());
  262.         
  263.         container->UpdateResource();
  264.     }        
  265. }
  266.  
  267.  
  268.